// src/store/index.js
import { createStore } from 'vuex'

import cartModule from './modules/cart';
import userModule from './modules/user';

const store = createStore({
  module:{
    user:userModule,
    cart:cartModule
  },
  state:{
    count:100
  },
  mutations: {
    addCounts(state,value){
        state.count+=value;
    },
    subCounts(state,value){
        state.count-=value;
    },
    setCounts(state,value){
        state.count = value;
    }
  },
  actions: {
    asyncAddCount(store,num){
        setTimeout(()=>{
            store.commit('addCounts',num)
        },1000)
    },
    asyncSubCount(store,num){
        setTimeout(()=>{
            store.commit('subCounts',num)
        },1000)
    }
  },
  getters: {
    doubleCount(state) {
      return state.count * 2
    }
  }
})

export default store